package com.gmlive.common.sample.share

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.gmlive.common.gmshare.GmShare
import com.gmlive.common.gmshare.base.IShareCallback
import com.gmlive.common.gmshare.bean.ShareEntity
import com.gmlive.common.gmshare.interfaces.ShareConstant
import com.gmlive.common.gmshare.share.QQShare
import com.gmlive.common.gmshare.share.WXShare
import com.gmlive.common.sample.R
import kotlinx.android.synthetic.main.activity_share.*

/**
 * Author: xs
 * Create on: 2020/04/07
 * Description: _
 */
class TestShareActivity : AppCompatActivity() {
    private val IMAGE_URL = "/storage/emulated/0/DCIM/Camera/JanePhoto_1563540251843.jpg"
    private var icon: Bitmap? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_share)

        icon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher)

        val testBean = ShareEntity("GMShare", "封装常用分享平台的sdk，统一并简化各分享sdk使用，提升分享功能的开发速度")
        testBean.url = "https://www.baidu.com" // 分享链接
        testBean.imgUrl = "https://www.baidu.com/img/bd_logo1.png"

        share_qq.setOnClickListener {
            GmShare.share(QQShare, this, ShareConstant.SHARE_CHANNEL_QQ, testBean, mShareCallback)
        }
        share_qzone.setOnClickListener {
            GmShare.share(QQShare, this, ShareConstant.SHARE_CHANNEL_QZONE, testBean, mShareCallback)
        }
        share_weixin.setOnClickListener {
            GmShare.share(WXShare, this, ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND, testBean, mShareCallback)
        }
        share_wxcircle.setOnClickListener {
            GmShare.share(WXShare, this, ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE, testBean, mShareCallback)
        }
    }


    private val mShareCallback = object : IShareCallback {
        override fun success(channel: Int) {
            showToast(channel, "分享成功-")
        }

        override fun failed(channel: Int, code: Int, message: String?) {
            showToast(channel, "分享失败-message-")
        }

        override fun cancel(channel: Int) {
            showToast(channel, "取消分享-")
        }
    }

    fun showToast(channel: Int, toast: String) {
        var toastString = toast
        when (channel) {
            ShareConstant.SHARE_CHANNEL_QQ -> toastString += "QQ"
            ShareConstant.SHARE_CHANNEL_QZONE -> toastString += "QZONE"
            ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND -> toastString += "WEIXIN_FRIEND"
            ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE -> toastString += "WEIXIN_CIRCLE"
        }
        Toast.makeText(this@TestShareActivity, toastString, Toast.LENGTH_SHORT).show()
    }

}